package cn.it.xxx.demo;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import java.util.HashMap;
import java.util.Map;

import App.MyApplication;
import cn.it.xxx.Fragment.ClassifyFragment;
import cn.it.xxx.Fragment.DownloadFragment;
import cn.it.xxx.Fragment.HomeFragment;
import cn.it.xxx.Fragment.TalkFragment;

public class MainActivity extends Activity {


    Map<Integer, Fragment> fragments = new HashMap<Integer, Fragment>();
    RadioGroup mRadioGroup;
    Button mUser;
    Button mQuery;
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        mRadioGroup = (RadioGroup)this.findViewById(R.id.main_rg);
         mQuery = (Button)this.findViewById(R.id.main_bt_query);
         mUser = (Button)this.findViewById(R.id.main_bt_user);
        fragments.put(R.id.main_home_rb,new HomeFragment());
            fragments.put(R.id.main_douwload_rb,new DownloadFragment());
            fragments.put(R.id.main_talk_rb,new TalkFragment());
            fragments.put(R.id.main_classify_rb,new ClassifyFragment());

            mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    Fragment fragment = fragments.get(checkedId);
                    replaceFragment(fragment);
                }
            });
            RadioButton button=(RadioButton) mRadioGroup.getChildAt(1);
            button.setChecked(true);

        mQuery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MyApplication.getContext(),QueryActivity.class);
                startActivity(intent);
            }
        });
        mUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MyApplication.getContext(),UserActivity.class);
                startActivity(intent);
            }
        });

    }






    private void replaceFragment(Fragment fragment) {
        getFragmentManager().beginTransaction().replace(R.id.main_fragment_container, fragment)
                .commit();
    }









}
